﻿using Library.Core.Domain.Specification;
using Synthesize.BaseSet.Domain.Aggregation.Entity.Authority;
using System;
using System.Linq.Expressions;

namespace Synthesize.BaseSet.Domain.Specifications.Authority.Role
{
    /// <summary>
    /// 角色查询条件拼装
    /// </summary>
    public class GetRoleListSpceification : ISpecification<RoleInfoEntity>
    {

        private readonly string _name;

        public GetRoleListSpceification(string name)
        {
            _name = name;
        }
        public Expression<Func<RoleInfoEntity, bool>> SatisfiedBy()
        {
            Specification<RoleInfoEntity> spec = new TrueSpecification<RoleInfoEntity>();

            if (!string.IsNullOrEmpty(_name))
            {
                spec &= new DirectSpecification<RoleInfoEntity>(o => o.Name.Contains(_name.Trim()));
            }
            return spec.SatisfiedBy();
        }
    }
}
